package com.servlet;

import com.dao.*;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class insert extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf8");
        searchdao s=new searchdaoimpl();
        String fname=req.getParameter("fname");
        String sname=req.getParameter("sname");
        String zone=req.getParameter("zone");
        String account=req.getParameter("account");
        String pwd=req.getParameter("pwd");
        String pname=req.getParameter("pname");
        String syste=req.getParameter("system");
        String level=req.getParameter("level");
        String title=req.getParameter("title");
        String value=req.getParameter("value");
        String deposit=req.getParameter("deposit");
        String price=req.getParameter("price");
        String requuid = req.getParameter("token");
        String sessuuid = (String) req.getSession().getAttribute("uuid");
        req.getSession().removeAttribute("uuid");
        if(requuid.equals(sessuuid)) {
            goodsmanagedao g = new goodsmanagedapimpl();
            int i = g.insert(fname, sname, account, pwd, value, price, zone, s.searchcookie(req), deposit, syste, title, level, pname);
            String s1 = Integer.toString(i);
            req.getSession().removeAttribute("token");
            req.setAttribute("xinxi", s1);
        }
        req.getRequestDispatcher("/maihao.jsp").forward(req, resp);
    }
}
